﻿using Domain.Entities.Stocks;
using FluentMigrator;
using FrameworkCore.Extensions;

namespace AiBLSmartEdu.Module.SmartStockSense.API.Migrations;

[Migration(202410101123)]
public class StockAddColumn : ForwardOnlyMigration
{
    public override void Up()
    {
        Alter.Table(MigrationExpressions.GetTableName(typeof(LargeTrade)))
            .AddColumn(MigrationExpressions.ColumnNameFor<LargeTrade>(nameof(LargeTrade.StockId))).AsInt64().WithColumnDescription("外键：关联的股票StockID。")
            .AddColumn(MigrationExpressions.ColumnNameFor<LargeTrade>(nameof(LargeTrade.Timestamp))).AsDateTime().WithColumnDescription("交易时间戳。")
            .AddColumn(MigrationExpressions.ColumnNameFor<LargeTrade>(nameof(LargeTrade.Price))).AsDecimal().WithColumnDescription("交易价格。")
            .AddColumn(MigrationExpressions.ColumnNameFor<LargeTrade>(nameof(LargeTrade.Volume))).AsInt32().WithColumnDescription("交易量。");

        Alter.Table(MigrationExpressions.GetTableName(typeof(MinuteTrade)))
            .AddColumn(MigrationExpressions.ColumnNameFor<MinuteTrade>(nameof(MinuteTrade.StockId))).AsInt64().WithColumnDescription("外键：关联的股票StockID。")
            .AddColumn(MigrationExpressions.ColumnNameFor<MinuteTrade>(nameof(MinuteTrade.Timestamp))).AsDateTime().WithColumnDescription("交易时间戳。")
            .AddColumn(MigrationExpressions.ColumnNameFor<MinuteTrade>(nameof(MinuteTrade.Price))).AsDecimal().WithColumnDescription("交易价格。")
            .AddColumn(MigrationExpressions.ColumnNameFor<MinuteTrade>(nameof(MinuteTrade.Volume))).AsInt32().WithColumnDescription("交易量。");

        Alter.Table(MigrationExpressions.GetTableName(typeof(NewStockCalendar)))
            .AddColumn(MigrationExpressions.ColumnNameFor<NewStockCalendar>(nameof(NewStockCalendar.StockId))).AsInt64().WithColumnDescription("外键：关联的股票StockID。")
            .AddColumn(MigrationExpressions.ColumnNameFor<NewStockCalendar>(nameof(NewStockCalendar.IssueDate))).AsDateTime().WithColumnDescription("发行日期。")
            .AddColumn(MigrationExpressions.ColumnNameFor<NewStockCalendar>(nameof(NewStockCalendar.Price))).AsDecimal().WithColumnDescription("发行价格。")
            .AddColumn(MigrationExpressions.ColumnNameFor<NewStockCalendar>(nameof(NewStockCalendar.Shares))).AsInt32().WithColumnDescription("发行股份数。");

        Alter.Table(MigrationExpressions.GetTableName(typeof(OrderBook)))
            .AddColumn(MigrationExpressions.ColumnNameFor<OrderBook>(nameof(OrderBook.StockId))).AsInt64().WithColumnDescription("外键：关联的股票StockID。")
            .AddColumn(MigrationExpressions.ColumnNameFor<OrderBook>(nameof(OrderBook.Timestamp))).AsDateTime().WithColumnDescription("订单时间戳。")
            .AddColumn(MigrationExpressions.ColumnNameFor<OrderBook>(nameof(OrderBook.BuyPrice))).AsDecimal().WithColumnDescription("买入价格。")
            .AddColumn(MigrationExpressions.ColumnNameFor<OrderBook>(nameof(OrderBook.BuyVolume))).AsInt32().WithColumnDescription("买入量。")
            .AddColumn(MigrationExpressions.ColumnNameFor<OrderBook>(nameof(OrderBook.SellPrice))).AsDecimal().WithColumnDescription("卖出价格。")
            .AddColumn(MigrationExpressions.ColumnNameFor<OrderBook>(nameof(OrderBook.SellVolume))).AsInt32().WithColumnDescription("卖出量。");

        Alter.Table(MigrationExpressions.GetTableName(typeof(RealTimeTrade)))
            .AddColumn(MigrationExpressions.ColumnNameFor<RealTimeTrade>(nameof(RealTimeTrade.StockId))).AsInt64().WithColumnDescription("外键：关联的股票StockID。")
            .AddColumn(MigrationExpressions.ColumnNameFor<RealTimeTrade>(nameof(RealTimeTrade.Timestamp))).AsDateTime().WithColumnDescription("交易时间戳。")
            .AddColumn(MigrationExpressions.ColumnNameFor<RealTimeTrade>(nameof(RealTimeTrade.Price))).AsDecimal().WithColumnDescription("交易价格。")
            .AddColumn(MigrationExpressions.ColumnNameFor<RealTimeTrade>(nameof(RealTimeTrade.Volume))).AsInt32().WithColumnDescription("交易量。");

        Alter.Table(MigrationExpressions.GetTableName(typeof(Stock)))
           .AddColumn(MigrationExpressions.ColumnNameFor<Stock>(nameof(Stock.StockCode))).AsString(10).WithColumnDescription("股票代码。")
           .AddColumn(MigrationExpressions.ColumnNameFor<Stock>(nameof(Stock.StockName))).AsString(100).WithColumnDescription("股票名称。")
           .AddColumn(MigrationExpressions.ColumnNameFor<Stock>(nameof(Stock.Market))).AsString(20).WithColumnDescription("市场类型（如：沪市/深市）。");

        Alter.Table(MigrationExpressions.GetTableName(typeof(TechnicalIndicator)))
            .AddColumn(MigrationExpressions.ColumnNameFor<TechnicalIndicator>(nameof(TechnicalIndicator.StockId))).AsInt64().WithColumnDescription("外键：关联的股票StockID。")
            .AddColumn(MigrationExpressions.ColumnNameFor<TechnicalIndicator>(nameof(TechnicalIndicator.Timestamp))).AsDateTime().WithColumnDescription("指标计算时间戳。")
            .AddColumn(MigrationExpressions.ColumnNameFor<TechnicalIndicator>(nameof(TechnicalIndicator.IndicatorType))).AsString(10).WithColumnDescription("指标类型（如：KDJ、MACD、MA、BOLL）。")
            .AddColumn(MigrationExpressions.ColumnNameFor<TechnicalIndicator>(nameof(TechnicalIndicator.Value))).AsDecimal().WithColumnDescription("指标值。");

        Alter.Table(MigrationExpressions.GetTableName(typeof(TickTrade)))
            .AddColumn(MigrationExpressions.ColumnNameFor<TickTrade>(nameof(TickTrade.StockId))).AsInt64().WithColumnDescription("外键：关联的股票StockID。")
            .AddColumn(MigrationExpressions.ColumnNameFor<TickTrade>(nameof(TickTrade.Timestamp))).AsDateTime().WithColumnDescription("成交时间戳。")
            .AddColumn(MigrationExpressions.ColumnNameFor<TickTrade>(nameof(TickTrade.Price))).AsDecimal().WithColumnDescription("成交价格。")
            .AddColumn(MigrationExpressions.ColumnNameFor<TickTrade>(nameof(TickTrade.Volume))).AsInt32().WithColumnDescription("成交量。");
    }
}
